const successData = {
  code: 1,
  message: 'success',
};
const errorData = {
  code: -1,
  message: 'err',
};

function successRes(data) {
  successData.data = data;
  return successData;
}

function errorRes(data) {
  errorData.data = data;
  return errorData;
}

function log(msg) {
  console.log(msg);
}

/// 获取本机ip
function getIPAdress() {
  const os = require('os');
  const interfaces = os.networkInterfaces();
  for (const devName in interfaces) {
    const iface = interfaces[devName];
    for (let i = 0; i < iface.length; i++) {
      const alias = iface[i];
      if (
        alias.family === 'IPv4' &&
        alias.address !== '127.0.0.1' &&
        !alias.internal
      ) {
        return alias.address;
      }
    }
  }
}

exports.successRes = successRes;
exports.errorRes = errorRes;
exports.log = log;
exports.getIPAdress = getIPAdress;
